package com.ctsi.organise.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.organise.entity.Person_Organise;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;


/**
 * Person_Organise Service 类
 * @author   zhangjw
 * @description  Person_Organise
 * @created	 Sun Nov 11 19:56:19 CST 2018
 */

@Repository
public class Person_OrganiseManager {
	private static final Logger logger=LoggerFactory.getLogger(Person_OrganiseManager.class);
	@Autowired
	private MybatisGenericDao dao;
	
	/**
	 * 添加
	 */
	public void insertPerson_Organise(Person_Organise person_Organise){
		if(UtilValidate.isEmpty(person_Organise.getId()))
			person_Organise.setId(UUIDGenerator.getId());
		logger.debug("insert {}",person_Organise);
		dao.insert(person_Organise);
	}	
	/**
	 * 动态更新
	 */	
	public int updatePerson_OrganiseByPKSelective(Person_Organise person_Organise){
		logger.debug("updateByPrimaryKeySelective {}",person_Organise);
		return dao.update(Person_Organise.class.getName()+".updateByPrimaryKeySelective", person_Organise);
	}
	/**
	 * 更新
	 */
	public int updatePerson_Organise(Person_Organise person_Organise){
		logger.debug("update {}",person_Organise);
		return dao.update(person_Organise);
	}
	
	
	public Person_Organise editPerson_OrganiseById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("editById {}",id);
		return (Person_Organise)dao.queryForObject(Person_Organise.class.getName()+".edit", id);
	}
	/**
	 * 根据ID查找 Person_Organise对象
	 */
	public Person_Organise findPerson_OrganiseById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(Person_Organise.class, id);
	}
	/**
	 * 删除Person_Organise对象
	 */
	public int removePerson_Organise(String id){	
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(Person_Organise.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}

    /**
     * 删除用户和组织的关联关系
     * @param organiseId
     * @param personId
     * @return
     */
	public int removePerson_Orgainse(String organiseId,String personId){
        // TODO: 完成物理删除
	    return 0;
    }
	
	/**
	 * 详细页查询
	 */
	public Person_Organise findByDetail(String id){
		return (Person_Organise)dao.queryForObject(Person_Organise.class.getName()+".findByDetail",id);
	}
	/** 
	 * 多条件查询结果 
	 */
	public Page<Person_Organise> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(Person_Organise.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/** 
	 * 多条件查询结果不分页
	 */
	public List<Person_Organise> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<Person_Organise>)dao.queryForList(Person_Organise.class.getName()+".selectByMap",map);
	}

}
